package com.starmark.flow.sys.org.web;


import com.starmark.common.base.util.BeanMapper;
import com.starmark.flow.sys.org.entity.SysOrgUser;
import com.starmark.flow.sys.org.service.ISysOrgUserService;
import com.starmark.flow.sys.org.vo.SysOrgUserPageQueryVo;
import com.starmark.flow.sys.org.vo.SysOrgUserPageVo;
import com.starmark.flow.sys.org.vo.SysOrgUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户管理控制器
 */
@RestController
@Api(value = "用户管理", description = "用户管理")
@RequestMapping(value = "/sys/org/user")
public class SysOrgUserController  {

    @Autowired
    private ISysOrgUserService sysOrgUserService;


    @ApiOperation(value = "查询用户")
    @PostMapping(value = "/query")
    public Object query(@RequestBody SysOrgUserPageQueryVo pageQueryVo) {

        return BeanMapper.mapPage(sysOrgUserService.queryPage(pageQueryVo), SysOrgUserPageVo.class);
    }


    @ApiOperation(value = "新增用户")
    @PostMapping
    public SysOrgUserVo save(@RequestBody SysOrgUserVo sysOrgUserVo) {
        String userId = sysOrgUserService.saveUserInfo(sysOrgUserVo);
        sysOrgUserVo.setId(userId);
        return sysOrgUserVo;
    }

    @ApiOperation(value = "用户详情")
    @GetMapping(value = "/{id}")
    public SysOrgUserVo get(@PathVariable("id") String id) {
        SysOrgUser sysOrgUser = sysOrgUserService.getById(id);
        return BeanMapper.map(sysOrgUser, SysOrgUserVo.class);

    }

    @PutMapping
    @ApiOperation(value = "修改用户")
    public Object update(@RequestBody SysOrgUserVo sysOrgUserVo) {
        sysOrgUserService.updateUserInfo(sysOrgUserVo);
        return sysOrgUserVo;
    }



    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "删除用户")
    public void delete(@PathVariable("id") String id) {
        sysOrgUserService.removeById(id);
    }


    @PostMapping(value = "/delete")
    @ApiOperation(value = "批量删除用户")
    public void deleteByIds(@RequestBody List<String> ids) {
        sysOrgUserService.removeByIds(ids);


    }
}
